package com.github.gin.sns.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.gin.sns.annotation.Keyword;
import com.github.gin.sns.util.MeiDoTalk;
import com.github.gin.sns.util.TuringTalk;
import com.github.gin.sns.util.XStreamUtil;
import com.github.gin.sns.vo.MsgType;
import com.github.gin.sns.vo.req.ITextMessage;
import com.github.gin.sns.vo.response.OTextMessage;

/**
 * Created by GinPonson on 2017/1/1.
 */
public class TextMessageService {

    public static String process(ITextMessage message){
        String resxml = "";
        JSONObject object = JSON.parseObject(MeiDoTalk.talk(message.getContent()));
        System.out.println(object.toJSONString());
        if(object != null ){
            // 回复文本消息
            OTextMessage textMessage = new OTextMessage();
            textMessage.setToUserName(message.getFromUserName());
            textMessage.setFromUserName(message.getToUserName());
            textMessage.setCreateTime();
            textMessage.setMsgType(MsgType.MESSAGE_TYPE_TEXT);
            /*if(content == null || "".equals(content)){
                textMessage.setContent("你再回复这些表情人家就不理你~\\(≧▽≦)/~啦啦啦");
            } else {*/
                textMessage.setContent(object.getString("ret_message"));
            //}
            resxml = XStreamUtil.getInstance().toXML(textMessage);
        }
        System.out.println(resxml);
       return resxml;
    }

    @Keyword()
    public static String p(){
        return "";
    }
}
